/*
 *  Copyright (c) 2011, StripBandunk and/or its affiliates. All rights reserved.
 * 
 *       http://stripbandunk.com/
 * 
 *  STRIPBANDUNK PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package stripbandunk.tutorial.jtreehibernate.helper;

import java.util.Collection;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import stripbandunk.tutorial.jtreehibernate.entity.Category;

/**
 *
 * @author echo
 */
public class CategoryTreeCreator {

    private DefaultTreeModel model;

    private DefaultMutableTreeNode root;

    public CategoryTreeCreator(String rootName) {
        root = new DefaultMutableTreeNode(rootName);
        model = new DefaultTreeModel(root);
    }

    public void addAll(Collection<Category> collection) {
        for (Category category : collection) {
            add(category);
        }
    }

    public void add(Category category) {
        root.add(new DefaultMutableTreeNode(category));
    }

    public DefaultTreeModel getModel() {
        return model;
    }
}
